package com.rdxer.api;

import com.rdxer.api.para.AnswerScorePara;
import com.rdxer.api.para.CommitAnswerSheetReqstBody;
import com.rdxer.core.entity.Result;
import com.rdxer.core.entity.StatusCode;
import com.rdxer.core.security.AppUserDetails;
import com.rdxer.dataview.AnswerSheetDV;
import com.rdxer.dataview.PaperQuestionDV;
import com.rdxer.model.AnswerSheet;
import com.rdxer.service.AnswerSheetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * departmentManagement
 */
@RestController
@CrossOrigin
@RequestMapping("/answerSheet")
public class AnswerSheetApi {

	@Autowired
	private AnswerSheetService service;

	@PostMapping("/answerid/{answerid}/score")
	public Result<?> answerScore(@PathVariable String answerid, @RequestBody AnswerScorePara para){
		boolean b = service.setAnswerScore(answerid, para.getScore());
		return new Result<>(true, StatusCode.OK,"查询成功",b);
	}


	@GetMapping("/paper/{paperId}/answerSheet/{id}")
	public Result<List<PaperQuestionDV>> getPaperQuestionDataAndV(@PathVariable String paperId, @PathVariable String id){
		return new Result<List<PaperQuestionDV>>(true, StatusCode.OK,"查询成功",service.findPaperQuestionDataAndV(paperId,id));
	}

	@GetMapping("/{id}")
	public Result<AnswerSheet> getById(@PathVariable String id){
		return new Result(true, StatusCode.OK,"查询成功",service.findById(id));
	}

	@GetMapping("/ByPaper/{id}")
	public Result<AnswerSheet> getByByPaperId(@PathVariable String id){
		return new Result(true, StatusCode.OK,"查询成功",service.getAnswerSheetByPaperAndUserId(id,AppUserDetails.getCurrent().account.getId()));
	}

	@PostMapping("/{id}/commit")
	public Result<?> commit(@PathVariable String id,@RequestBody CommitAnswerSheetReqstBody data){
		AnswerSheet commit = service.commit(id, data.getData());
		return new Result(true, StatusCode.OK,"查询成功",commit);
	}

	@GetMapping("/all")
	public Result<List<AnswerSheetDV>> all(){
		return new Result(true, StatusCode.OK,"查询成功",service.getAnswerSheetDVListByUserId(AppUserDetails.getCurrent().account.getId()));
	}
}
